from FPCheck import *
from FPPattern import *
from log import log

class FPEntity(object):
	fppatterns={}
	score=0
	threshold=10
	name=''
	value=1
	def __init__(self,name,value,threshold=10):
		self.threshold=threshold
		self.name=name
		self.value=value

	def add_fppattern(self,fppattern):
		self.fppatterns[fppattern.pattern]=fppattern

	def add_fppattern(self,pattern, value, type):
		self.fppatterns[pattern]=FPPattern(pattern,value,type)

	def get_score(self,fpchecks):
		for fppattern in self.fppatterns.values():
			if fpchecks[fppattern.pattern].matched>0:
				self.score=self.score+fpchecks[fppattern.pattern].matched*fppattern.value
				log("Updating Ent " + self.name+ " score with "+ str(fpchecks[fppattern.pattern].matched)+ "*"+str(fppattern.value))
		return self.score

	def clear(self):
		self.score=0

	def is_alert(self):
		if self.score>self.threshold:
			return 1
		else:
			return 0

	def get_fpchecks(self):
		fpchecks={}
		for i in self.fppatterns.values():
			fpchecks[i.pattern]=i.get_fpcheck()
			log ("Adding fpcheck for " + i.pattern)
		return fpchecks

